package reflect;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

/**
 * 实例化10个Person对象，使用反射
 *
 */
public class Test1 {
    public static void main(String[] args) throws Exception {
        List<Person> list = new ArrayList<>();
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class,int.class);

        for (int i = 0; i <10 ; i++) {
            Person p = (Person)c.newInstance("test"+(i+1),21+i);
            list.add(p);
        }
        System.out.println(list);
    }
}
